import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _omit from "lodash/omit";
import { getResponse } from 'utils/utils';
import { queryTree as _queryTree, queryGroup as _queryGroup, queryUnitDetails as _queryUnitDetails, queryCode as _queryCode, queryModule as _queryModule, saveFieldIndividual as _saveFieldIndividual, deleteFieldIndividual as _deleteFieldIndividual, queryFieldMapping as _queryFieldMapping, queryConditions as _queryConditions, queryRelatedUnits as _queryRelatedUnits, querySelfValidator as _querySelfValidator, saveSelfValidator as _saveSelfValidator, saveHeaderIndividual as _saveHeaderIndividual } from "../services/customizeConfigService";
import { queryMapIdpValue } from 'services/api';
export default {
  namespace: 'configCustomize',
  state: {
    treeData: [],
    unitGroup: [],
    currentUnit: {
      config: {}
    },
    lineData: [],
    unitAlias: [],
    moduleList: [],
    codes: {
      dateFormat: [],
      whereOption: [],
      renderOptions: [],
      fieldWidget: [],
      custType: [],
      custTypeObj: {},
      fieldType: [],
      fixed: [],
      fixedObj: {},
      fieldWidgetObj: {},
      unitType: [],
      unitTypeObj: {},
      condOptions: []
    },
    // 高级校验-条件列表 & 校验器列表
    headerProps: {},
    conditionList: [],
    validatorList: []
  },
  effects: {
    queryCodes: /*#__PURE__*/_regeneratorRuntime.mark(function queryCodes(_ref, _ref2) {
      var payload, call, put, res, fixedObj, fieldWidgetObj, unitTypeObj, custTypeObj;
      return _regeneratorRuntime.wrap(function queryCodes$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              _context.t0 = getResponse;
              _context.next = 5;
              return call(queryMapIdpValue, payload);

            case 5:
              _context.t1 = _context.sent;
              res = (0, _context.t0)(_context.t1);

              if (!res) {
                _context.next = 18;
                break;
              }

              fixedObj = {};
              fieldWidgetObj = {};
              unitTypeObj = {};
              custTypeObj = {};
              res.fixed.forEach(function (i) {
                fixedObj[i.value] = i.meaning;
              });
              res.fieldWidget.forEach(function (i) {
                fieldWidgetObj[i.value] = i.meaning;
              });
              res.unitType.forEach(function (i) {
                unitTypeObj[i.value] = i.meaning;
              });
              res.custType.forEach(function (i) {
                custTypeObj[i.value] = i.meaning;
              });
              _context.next = 18;
              return put({
                type: 'updateState',
                payload: {
                  codes: _objectSpread(_objectSpread({}, res), {}, {
                    fixedObj: fixedObj,
                    fieldWidgetObj: fieldWidgetObj,
                    unitTypeObj: unitTypeObj,
                    custTypeObj: custTypeObj
                  })
                }
              });

            case 18:
            case "end":
              return _context.stop();
          }
        }
      }, queryCodes);
    }),
    queryTree: /*#__PURE__*/_regeneratorRuntime.mark(function queryTree(_ref3, _ref4) {
      var payload, call, put, res;
      return _regeneratorRuntime.wrap(function queryTree$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call, put = _ref4.put;
              _context2.t0 = getResponse;
              _context2.next = 5;
              return call(_queryTree, payload);

            case 5:
              _context2.t1 = _context2.sent;
              res = (0, _context2.t0)(_context2.t1);

              if (!res) {
                _context2.next = 10;
                break;
              }

              _context2.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  treeData: res
                }
              });

            case 10:
            case "end":
              return _context2.stop();
          }
        }
      }, queryTree);
    }),
    queryCode: /*#__PURE__*/_regeneratorRuntime.mark(function queryCode(_ref5, _ref6) {
      var payload, call, put, res;
      return _regeneratorRuntime.wrap(function queryCode$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref5.payload;
              call = _ref6.call, put = _ref6.put;
              _context3.t0 = getResponse;
              _context3.next = 5;
              return call(_queryCode, payload);

            case 5:
              _context3.t1 = _context3.sent;
              res = (0, _context3.t0)(_context3.t1);

              if (!res) {
                _context3.next = 10;
                break;
              }

              _context3.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  codes: res
                }
              });

            case 10:
            case "end":
              return _context3.stop();
          }
        }
      }, queryCode);
    }),
    queryGroup: /*#__PURE__*/_regeneratorRuntime.mark(function queryGroup(_ref7, _ref8) {
      var payload, call, put, res;
      return _regeneratorRuntime.wrap(function queryGroup$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref7.payload;
              call = _ref8.call, put = _ref8.put;
              _context4.t0 = getResponse;
              _context4.next = 5;
              return call(_queryGroup, payload);

            case 5:
              _context4.t1 = _context4.sent;
              res = (0, _context4.t0)(_context4.t1);

              if (!res) {
                _context4.next = 10;
                break;
              }

              _context4.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  unitGroup: res || []
                }
              });

            case 10:
              return _context4.abrupt("return", res);

            case 11:
            case "end":
              return _context4.stop();
          }
        }
      }, queryGroup);
    }),
    queryUnitDetails: /*#__PURE__*/_regeneratorRuntime.mark(function queryUnitDetails(_ref9, _ref10) {
      var payload, call, put, res;
      return _regeneratorRuntime.wrap(function queryUnitDetails$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref9.payload;
              call = _ref10.call, put = _ref10.put;
              _context5.t0 = getResponse;
              _context5.next = 5;
              return call(_queryUnitDetails, payload);

            case 5:
              _context5.t1 = _context5.sent;
              res = (0, _context5.t0)(_context5.t1);

              if (!res) {
                _context5.next = 12;
                break;
              }

              _context5.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  currentUnit: res.unit || {
                    config: {}
                  },
                  lineData: res.configFields || [],
                  unitAlias: res.unitAlias || []
                }
              });

            case 10:
              _context5.next = 14;
              break;

            case 12:
              _context5.next = 14;
              return put({
                type: 'updateState',
                payload: {
                  currentUnit: {
                    config: {}
                  },
                  lineData: [],
                  unitAlias: []
                }
              });

            case 14:
              return _context5.abrupt("return", res);

            case 15:
            case "end":
              return _context5.stop();
          }
        }
      }, queryUnitDetails);
    }),
    queryModule: /*#__PURE__*/_regeneratorRuntime.mark(function queryModule(_ref11, _ref12) {
      var payload, call, put, res;
      return _regeneratorRuntime.wrap(function queryModule$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref11.payload;
              call = _ref12.call, put = _ref12.put;
              _context6.t0 = getResponse;
              _context6.next = 5;
              return call(_queryModule, payload);

            case 5:
              _context6.t1 = _context6.sent;
              res = (0, _context6.t0)(_context6.t1);

              if (!res) {
                _context6.next = 10;
                break;
              }

              _context6.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  moduleList: res
                }
              });

            case 10:
            case "end":
              return _context6.stop();
          }
        }
      }, queryModule);
    }),
    queryFieldMapping: /*#__PURE__*/_regeneratorRuntime.mark(function queryFieldMapping(_ref13, _ref14) {
      var payload, call;
      return _regeneratorRuntime.wrap(function queryFieldMapping$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref13.payload;
              call = _ref14.call;
              _context7.t0 = getResponse;
              _context7.next = 5;
              return call(_queryFieldMapping, payload);

            case 5:
              _context7.t1 = _context7.sent;
              return _context7.abrupt("return", (0, _context7.t0)(_context7.t1));

            case 7:
            case "end":
              return _context7.stop();
          }
        }
      }, queryFieldMapping);
    }),
    queryConditions: /*#__PURE__*/_regeneratorRuntime.mark(function queryConditions(_ref15, _ref16) {
      var payload, call;
      return _regeneratorRuntime.wrap(function queryConditions$(_context8) {
        while (1) {
          switch (_context8.prev = _context8.next) {
            case 0:
              payload = _ref15.payload;
              call = _ref16.call;
              _context8.t0 = getResponse;
              _context8.next = 5;
              return call(_queryConditions, payload);

            case 5:
              _context8.t1 = _context8.sent;
              return _context8.abrupt("return", (0, _context8.t0)(_context8.t1));

            case 7:
            case "end":
              return _context8.stop();
          }
        }
      }, queryConditions);
    }),
    queryRelatedUnits: /*#__PURE__*/_regeneratorRuntime.mark(function queryRelatedUnits(_ref17, _ref18) {
      var payload, call;
      return _regeneratorRuntime.wrap(function queryRelatedUnits$(_context9) {
        while (1) {
          switch (_context9.prev = _context9.next) {
            case 0:
              payload = _ref17.payload;
              call = _ref18.call;
              _context9.t0 = getResponse;
              _context9.next = 5;
              return call(_queryRelatedUnits, payload);

            case 5:
              _context9.t1 = _context9.sent;
              return _context9.abrupt("return", (0, _context9.t0)(_context9.t1));

            case 7:
            case "end":
              return _context9.stop();
          }
        }
      }, queryRelatedUnits);
    }),
    saveFieldIndividual: /*#__PURE__*/_regeneratorRuntime.mark(function saveFieldIndividual(_ref19, _ref20) {
      var payload, call;
      return _regeneratorRuntime.wrap(function saveFieldIndividual$(_context10) {
        while (1) {
          switch (_context10.prev = _context10.next) {
            case 0:
              payload = _ref19.payload;
              call = _ref20.call;
              _context10.t0 = getResponse;
              _context10.next = 5;
              return call(_saveFieldIndividual, payload);

            case 5:
              _context10.t1 = _context10.sent;
              return _context10.abrupt("return", (0, _context10.t0)(_context10.t1));

            case 7:
            case "end":
              return _context10.stop();
          }
        }
      }, saveFieldIndividual);
    }),
    saveHeaderIndividual: /*#__PURE__*/_regeneratorRuntime.mark(function saveHeaderIndividual(_ref21, _ref22) {
      var payload, call;
      return _regeneratorRuntime.wrap(function saveHeaderIndividual$(_context11) {
        while (1) {
          switch (_context11.prev = _context11.next) {
            case 0:
              payload = _ref21.payload;
              call = _ref22.call;
              _context11.t0 = getResponse;
              _context11.next = 5;
              return call(_saveHeaderIndividual, payload);

            case 5:
              _context11.t1 = _context11.sent;
              return _context11.abrupt("return", (0, _context11.t0)(_context11.t1));

            case 7:
            case "end":
              return _context11.stop();
          }
        }
      }, saveHeaderIndividual);
    }),
    deleteFieldIndividual: /*#__PURE__*/_regeneratorRuntime.mark(function deleteFieldIndividual(_ref23, _ref24) {
      var payload, call;
      return _regeneratorRuntime.wrap(function deleteFieldIndividual$(_context12) {
        while (1) {
          switch (_context12.prev = _context12.next) {
            case 0:
              payload = _ref23.payload;
              call = _ref24.call;
              _context12.t0 = getResponse;
              _context12.next = 5;
              return call(_deleteFieldIndividual, payload);

            case 5:
              _context12.t1 = _context12.sent;
              return _context12.abrupt("return", (0, _context12.t0)(_context12.t1));

            case 7:
            case "end":
              return _context12.stop();
          }
        }
      }, deleteFieldIndividual);
    }),
    querySelfValidator: /*#__PURE__*/_regeneratorRuntime.mark(function querySelfValidator(_ref25, _ref26) {
      var payload, call, put, res;
      return _regeneratorRuntime.wrap(function querySelfValidator$(_context13) {
        while (1) {
          switch (_context13.prev = _context13.next) {
            case 0:
              payload = _ref25.payload;
              call = _ref26.call, put = _ref26.put;
              _context13.t0 = getResponse;
              _context13.next = 5;
              return call(_querySelfValidator, payload);

            case 5:
              _context13.t1 = _context13.sent;
              res = (0, _context13.t0)(_context13.t1);

              if (!res) {
                _context13.next = 10;
                break;
              }

              _context13.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  headerProps: _omit(res, ['lines', 'valids']),
                  conditionList: res.lines || [],
                  validatorList: res.valids || []
                }
              });

            case 10:
              return _context13.abrupt("return", res);

            case 11:
            case "end":
              return _context13.stop();
          }
        }
      }, querySelfValidator);
    }),
    saveSelfValidator: /*#__PURE__*/_regeneratorRuntime.mark(function saveSelfValidator(_ref27, _ref28) {
      var payload, call;
      return _regeneratorRuntime.wrap(function saveSelfValidator$(_context14) {
        while (1) {
          switch (_context14.prev = _context14.next) {
            case 0:
              payload = _ref27.payload;
              call = _ref28.call;
              _context14.t0 = getResponse;
              _context14.next = 5;
              return call(_saveSelfValidator, payload);

            case 5:
              _context14.t1 = _context14.sent;
              return _context14.abrupt("return", (0, _context14.t0)(_context14.t1));

            case 7:
            case "end":
              return _context14.stop();
          }
        }
      }, saveSelfValidator);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref29) {
      var payload = _ref29.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};